<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button class="filter-item" type="success" @click="handleSubmit"> 保存 </el-button>
    </div>
    <div class="grid">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>基本信息</span>
        </div>
        <el-form :model="device">
          <el-form-item label="名称" :label-width="formLabelWidth">
            <el-input v-model="device.name" autocomplete="off" />
          </el-form-item>
          <el-form-item label="自动获取距离-轴名称" :label-width="formLabelWidth">
            <el-input v-model="device.value.condition.DistanceAxisName" autocomplete="off" />
          </el-form-item>
        </el-form>
      </el-card>

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <h3>空气比释动能率计算-条件选项</h3>
        </div>
        <el-table :data="device.value.tableDataAirKermaCondition" stripe border style="width: 100%">
          <el-table-column prop="TubeVoltage" label="管电压(kV)" />
          <el-table-column prop="Attenuator" label="衰减片" />
          <el-table-column prop="TubeCurrent" label="管电流(mA)" />
          <el-table-column prop="Distance" label="距离(m)" />
          <el-table-column prop="Nc" label="修正因子/Nc" />
          <el-table-column prop="Time" label="照射时间" />
        </el-table>
        <upload-excel-component :on-success="handleSuccessExcelAirKermaCondition" :before-upload="beforeUploadExcel" />
      </el-card>

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <h3>空气比释动能率计算-默认</h3>
        </div>
        <el-table
          :data="device.value.tableDataAirKermaDefault"
          stripe
          border
          style="width: 100%"
        >
          <el-table-column prop="TubeVoltage" label="管电压(kV)" />
          <el-table-column prop="Attenuator" label="衰减片" />
          <el-table-column prop="TubeCurrent" label="管电流(mA)" />
          <el-table-column prop="K_1" label="K_1" />
          <el-table-column prop="N1" label="N1" />
          <el-table-column prop="N2" label="N2" />
          <el-table-column prop="N3" label="N3" />
          <el-table-column prop="N4" label="N4" />
          <el-table-column prop="N5" label="N5" />
          <el-table-column prop="N6" label="N6" />
          <el-table-column prop="N7" label="N7" />
          <el-table-column prop="N8" label="N8" />
          <el-table-column prop="N9" label="N9" />
          <el-table-column prop="N10" label="N10" />
        </el-table>
        <upload-excel-component :on-success="handleSuccessExcelAirKermaDefault" :before-upload="beforeUploadExcel" />
      </el-card>

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <h3>空气比释动能率计算-自定义</h3>
        </div>
        <el-table
          :data="device.value.tableDataAirKermaCustom"
          stripe
          border
          style="width: 100%"
        >
          <el-table-column prop="TubeVoltage" label="管电压(kV)" />
          <el-table-column prop="Attenuator" label="衰减片" />
          <el-table-column prop="TubeCurrent" label="管电流(mA)" />
          <el-table-column prop="K_1" label="K_1" />
          <el-table-column prop="N1" label="N1" />
          <el-table-column prop="N2" label="N2" />
          <el-table-column prop="N3" label="N3" />
          <el-table-column prop="N4" label="N4" />
          <el-table-column prop="N5" label="N5" />
          <el-table-column prop="N6" label="N6" />
          <el-table-column prop="N7" label="N7" />
          <el-table-column prop="N8" label="N8" />
          <el-table-column prop="N9" label="N9" />
          <el-table-column prop="N10" label="N10" />
        </el-table>
        <upload-excel-component :on-success="handleSuccessExcelAirKermaCustom" :before-upload="beforeUploadExcel" />
      </el-card>

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <h3>周围剂量当量率计算</h3>
        </div>
        <el-table
          :data="device.value.tableDataDose"
          stripe
          border
          style="width: 100%"
        >
          <el-table-column prop="Radio" label="辐射质" />
          <el-table-column prop="Distance" label="照射距离/m" />
          <el-table-column prop="H_K_10" label="h_k(10)/Sv*Gy-1" />
        </el-table>
        <upload-excel-component :on-success="handleSuccessExcelDose" :before-upload="beforeUploadExcel" />
      </el-card>
    </div>

  </div>
</template>

<script>
import { editDevice } from '@/api/device'
import UploadExcelComponent from './components/UploadExcel/index.vue'

const defaultDeviceConfig = {
  name: 'x射线空气比释动能率计算',
  sn: 'count_x0001',
  model: 'FSC_COUNT_X',
  tag: 'count_x',
  position: '位置',
  sub: 'fsc/count_x/count_x0001/rx',
  pub: 'fsc/count_x/count_x0001/tx',
  value: {
    tableAirKermaSelect: 0, // 0:默认， 1:自定义
    tableDataAirKermaDefault: [], // 默认表
    tableDataAirKermaCustom: [], // 自定义表
    tableDataAirKermaCondition: [], // 条件表
    tableDataDose: [], // 周围剂量当量表
    condition: { // 条件
      TubeVoltage: 60,
      Attenuator: 'N-60',
      TubeCurrent: 60,
      Distance: 1,
      DistanceAxisIndex: 1,
      DistanceAxisName: 'Y',
      Time: 1,
      Nc: 1
    },
    result: {
      Kd_rate: 0, // 空气比释动能率
      Kd: 0, // 空气比释动能
      Kd_unit: 'uGy',
      Hd_rate: 0, // 周围剂量当量率
      Hd: 0, // 周围剂量当量
      Hd_unit: 'uSv',
      time: 'h'
    },
    auto: true // 自动计算
  },
  online: 0,
  status: 0,
  lock: 0,
  order: 0
}

export default {
  name: 'RG601',
  components: { UploadExcelComponent },
  data() {
    return {
      formLabelWidth: '300px',
      device: defaultDeviceConfig
    }
  },
  created() {
    this.device = this.$route.query
  },
  methods: {
    // 提交保存
    handleSubmit() {
      editDevice(this.device).then(response => {
        if (response.code === 200) {
          this.$message({
            type: 'success',
            message: response.message
          })
          this.$router.push({ path: '/device/index' })
        } else this.$message(response.message)
      })
    },
    beforeUploadExcel(file) {
      const isLt1M = file.size / 1024 / 1024 < 1

      if (isLt1M) {
        return true
      }

      this.$message({
        message: 'Please do not upload files larger than 1m in size.',
        type: 'warning'
      })
      return false
    },
    handleSuccessExcelAirKermaDefault({ results, header }) {
      this.device.value.tableDataAirKermaDefault = results
    },
    handleSuccessExcelAirKermaCustom({ results, header }) {
      this.device.value.tableDataAirKermaCustom = results
    },
    handleSuccessExcelAirKermaCondition({ results, header }) {
      this.device.value.tableDataAirKermaCondition = results
    },
    handleSuccessExcelDose({ results, header }) {
      this.device.value.tableDataDose = results
    }

  }
}
</script>

<style lang="scss" scoped>
.box-card{
  margin-bottom: 20px;
}

.plus{
  min-width: 100%;
  min-height: 300px;
  text-align: center;
  font-size: 108px;
}

 .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
  }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.box-card{
  margin: 10px;
}

</style>
